// jquery.modal.js
(function ($) {
	$.fn.modal = function (options) {
		return this.each(function () {
			init($(this), options);
		});
	}

	function init (el, options) {
		render(el, options);
		bindEvents(el, options);
	}
	
	function render (el, options) {
		var modalTemplate = Application.Contenido.find('#jquery-modal').html(),
			template = options.template,
			data = options.data || { },
			compiled = _.template(template, data);

		el.remove('#modal-content').append(modalTemplate).find('#modal-content').html(compiled);

		return el;
	}
	
	function bindEvents (el, options) {
		var cerrarModal = function  (e) {
			e.preventDefault();
			el.find('#modal-shadow').remove();
			el.find('#modal-container').remove();
			history.go(-1);
            return true;
		};
		el.find('#close-button, #modal-shadow').on('click', cerrarModal);
	}
	
	
}(jQuery));
